Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Pinia | Vue3 - Accessing array in deep object

In Pinia (base.js)

export const useBaseStore = defineStore('base', {
state: () => {
    return {
        areaLocal: [
            { id: 0, name: 'LAX' },
            { id: 1, name: 'SFO' },
            { id: 2, name: 'SAN' },
        ],
        areaLocal2: {
            area: [
                { id: 0, name: 'AAA'},
                { id: 1, name: 'BBB'},
                { id: 2, name: 'CCC'},
        ]},
    }
},
getters: {
    getAreaById: (state) => {
        return (areaId) =>
            state.areaLocal.find((areaLocal) => areaLocal.id === areaId)
    },..

in Vue (area.vue)

<script setup>
import { computed, ref } from 'vue'
import { storeToRefs } from 'pinia'
import { useBaseStore } from '../stores/base'

const areaStore = useBaseStore()
const { getAreaById } = storeToRefs(areaStore)
const areaIndex = ref(0)
</script>
<template>
    <div class="container">
        <h2>AREA: {{ getAreaById(areaIndex).name }}</h2>
....

This, areaLocal, I get "AREA: LAX", which is correct, but HOW I can write "getter" in the pinia for access to "areaLocal2", the object "area" then the array?

state.areaLocal2.area.find((areaLocal2.area) => areaLocal.id.area === areaId

The above throws an undefined error.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

getArea2ById: (state) => (areaIa) => state.areaLocal2.area.find((area) => area.id === areaId)

You are already in area by the time you hit the find higher order function so no need to reference it again inside of it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!